﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>生成表单</title>
    <link href="/Themes/Styles/style.css" rel="stylesheet" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js"></script>
    <script src="/Themes/Scripts/common.js"></script>
    <script type="text/javascript">
        var type = GetQuery('type');//生成类型
        var db = GetQuery('db');//数据库
        var table = GetQuery('table');//表名
        var tableRemark = GetQuery('tableRemark');//表备注
        $(function () {
            Load();
            //***********生成类型 start***********
            $("#createPattern,#colPattern").hide();
            if (type == "form") $("#colPattern").show();
            if (type == "list") $("#createPattern").show();
            //***********生成类型 end***********

            $('.title').find('span').html(table + "，" + decodeURI(tableRemark));
        })
        //初始化
        function Load() {
            var rowindex = 1;
            var column, remark, length = "";
            var parm = "action=GetColumns&table=" + escape(table) + "&db=" + escape(db);
            Ajax('/Ajax/Common_Ajax.ashx', parm, function (data) {
                var json = eval("(" + data + ")");
                for (var i = 0; i < json.JSON.length; i++) {
                    var list = json.JSON[i];
                    column = list.COLUMN;                                         //字段
                    remark = list.REMARK;                                         //说明
                    length = list.LENGTH;                                         //长度

                    var tr = '<tr>';
                    tr += '<td class="td-div" style="width:30px; text-align: center;">' + rowindex + '</td>'
                    tr += '<td style="width:80px; text-align: center;"><a style="text-decoration:underline;cursor: pointer;" onclick="up(this);">上移</a style="text-decoration:underline;cursor: pointer;">&nbsp;&nbsp;<a style="text-decoration:underline;cursor: pointer;" onclick="down(this)">下移</a></td>'
                    tr += '<td style="width:40px; text-align: center;"><input id="Enabled_' + rowindex + '" onclick="IsEnabled(this.id,' + rowindex + ')"  type="checkbox" checked="checked" /></td>'
                    tr += '<td style="width:120px;"><input value=' + remark + ' id="Remark_' + rowindex + '" type="text" class="txt" /></td>'
                    tr += '<td style="width:120px;"><input value=' + column + ' id="Column_' + rowindex + '" type="text" class="txt" /></td>'
                    tr += '<td style="width:80px;"><select id="Type_' + rowindex + '" class="select" style="width:100%;"><option value="1">文本框</option><option value="2">下拉框</option><option value="3">日期框<option value="6">复选框</option</option><option value="4">标  签</option><option value="5">多行文本框</option></select></td>'
                    tr += '<td style="width:80px; text-align: center;"><input id="MaxLength_' + rowindex + '"  style="width:96%;text-align:center;" value="290px" id="Code➩' + rowindex + '" type="text" class="txt" style="text-align: center;" /></td>'
                    tr += '<td style="width:80px; text-align: center;"><input id="Length_' + rowindex + '" style="width:96%;text-align:center;" value=' + length + ' id="Code➩' + rowindex + '" type="text" class="txt" style="text-align: center;" /></td>'
                    tr += '<td style="width:200px; "><select id="Validator_' + rowindex + '" class="select"  ><option value="">允许为空</option><option value="NotNull">NotNull - 不能为空</option><option value="Num">Num - 必须为数字</option><option value="NumOrNull">NumOrNull - 必须为数字</option><option value="Phone">Phone - 必须电话格式！</option><option value="PhoneOrNull">PhoneOrNull - 必须电话格式！</option><option value="Mobile">Mobile - 必须为手机格式！</option><option value="MobileOrNull">MobileOrNull - 必须为手机格式！</option><option value="MobileOrPhoneOrNull">必须为电话格式或手机格式！</option><option value="Email">Email - 必须为E-mail格式！</option><option value="isEmailOrNull">EmailOrNull - 必须为E-mail格式！</option><option value="Date">Date - 必须为日期格式！</option><option value="DateOrNull">DateOrNull - 必须为日期格式！</option><option value="IDCard">IDCard - 必须为身份证格式！</option><option value="IDCardOrNull">IDCardOrNull - 必须为身份证格式！</option><option value="Double">Double - 必须为小数！</option><option value="DoubleOrNull">DoubleOrNull - 必须为小数！</option></select></td>'
                    tr += '</tr>';
                    $(tr).appendTo("#tb_Form #add_Table");
                    rowindex++;
                }
            });
        }
        //判断是否有效
        function IsEnabled(e, index) {
            if ($("#" + e).attr("checked") == 'checked') {
                $("#Remark_" + index, "#Column_" + index, "#Type_" + index, "#MaxLength_" + index, "#Length_" + index, "#Validator_" + index).removeAttr("disabled");
            }
            else {
                $("#Remark_" + index, "#Column_" + index, "#Type_" + index, "#MaxLength_" + index, "#Length_" + index, "#Validator_" + index).attr("disabled", "disabled");
            }
        }
        //获取表单信息
        function GetFrom() {
            var itemvalues = "";
            var index = 1;
            $("#tb_Form #add_Table tr").each(function () {
                if ($("#Column_" + index).attr("disabled") == undefined) {
                    $(this).find('td').each(function () {
                        var pk_id = $(this).find('input,select').attr('id');
                        if (pk_id != undefined) {
                            var pk_value = $("#" + pk_id).val();
                            var array = new Array();
                            array = pk_id.split("_"); //字符分割
                            itemvalues += array[0] + "=" + pk_value + "|";
                        }
                    })
                    itemvalues += "$";
                }
                index++;
            });
            return itemvalues;
        }
        //生成操作
        function CreateCode() {
            var columns = GetFrom();
            if (columns != "") {
                $("#hi_column").val(columns);//列数
                var columnnum = $("input:radio[name='rt_CType']:checked").val();
                var ispage = $("input:radio[name='rt_PageList']:checked").val();//是否分页
                var url = '/Bulid/Code_Browse.htm?type=' + type + '&table=' + escape(table) + '&tableRemark=' + escape(decodeURI(tableRemark)) + '&ispage=' + ispage + '&columnnum=' + columnnum;
                var tabId = "Code_Browse";
                CloseTab(tabId);
                AddTabMenu(tabId, url, '生成查看', 'page_white_csharp.png', 'true');
            }
        }
        //上移
        function up(obj) {
            var objParentTR = $(obj).parent().parent();
            var prevTR = objParentTR.prev();
            if (prevTR.length > 0) {
                prevTR.insertAfter(objParentTR);
            } else {
                return;
            }
        }
        //下移
        function down(obj) {
            var objParentTR = $(obj).parent().parent();
            var nextTR = objParentTR.next();
            if (nextTR.length > 0) {
                nextTR.insertBefore(objParentTR);
            } else {
                return;
            }
        }
    </script>
    <style>
        .txt {
            border: none;
        }
    </style>
</head>
<body>
    <form id="form1">
        <!--选择的列-->
        <input type="hidden" id="hi_column" />
        <div class="btnbarcontetn" style="margin-bottom: 1px;">
            <div class="title">
                <span style="color: #000000;">
                    BPMS_User，用户、帐户
                </span>
            </div>
        </div>
        <!--字段列表-->
        <div class="div-body" id="basicInfo" style="height: 400px; overflow-y: scroll;">
            <table id="tb_Form" class="grid" style="width: 100%;">
                <thead>
                    <tr>
                        <td style="width: 30px; text-align: center;"></td>
                        <td style="width: 80px; text-align: center;">操作</td>
                        <td style="width: 40px; text-align: center;">
                            有效
                        </td>
                        <td style="width: 120px;">
                            说明
                        </td>
                        <td style="width: 120px;">
                            控件ID
                        </td>
                        <td style="width: 80px;">
                            控件类型
                        </td>
                        <td style="width: 80px; text-align: center;">控件宽度px</td>
                        <td style="width: 80px; text-align: center;">
                            验证长度
                        </td>
                        <td style="width: 200px;">控件校验</td>
                    </tr>
                </thead>
                <tbody id="add_Table"></tbody>
            </table>
        </div>
        <!--列模式-->
        <fieldset id="colPattern" style="border: 1px solid #ccc;">
            <legend style="padding: 5px;">显示列数模式</legend>
            <div class="lbl_fie">
                <label>
                    <input type="radio" name="rt_CType" checked="checked" value="1" />一列
                </label>
                <label>
                    <input type="radio" name="rt_CType" value="2" />二列
                </label>
                <label>
                    <input type="radio" name="rt_CType" value="3" />三列
                </label>
                <label>
                    <input type="radio" name="rt_CType" value="4" />四列
                </label>
            </div>
        </fieldset>
        <!--生成模式-->
        <fieldset id="createPattern" style="border: 1px solid #ccc;">
            <legend style="padding: 5px;">生成模式</legend>
            <div class="lbl_fie">
                <label>
                    <input type="radio" name="rt_PageList" value="1" checked="checked" />分页
                </label>
                <label>
                    <input type="radio" name="rt_PageList" value="0" />不分页
                </label>
            </div>
        </fieldset>
        <div class="aui_buttons">
            <span id="btnCreate" class="btn_span" onclick="CreateCode();">生成操作</span>
        </div>
    </form>
</body>
</html>
